home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18456 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: howland.reston.ans.net!psinntp!psinntp!psinntp!psinntp!usenet
  2. From: grantp@usa.pipeline.com(Pete Grant)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: execution speed of c++ versus c
  5. Date: 20 Apr 1996 18:03:25 GMT
  6. Organization: Kalevi, Inc.
  7. Message-ID: <4lb8td$3o4@news1.h1.usa.pipeline.com>
  8. References: <4l8k1q$mji@news.missouri.edu>
  9. NNTP-Posting-Host: 38.8.60.8
  10. X-PipeUser: grantp
  11. X-PipeHub: usa.pipeline.com
  12. X-PipeGCOS: (Pete Grant)
  13. X-Newsreader: Pipeline v3.5.0
  14.  
  15. On Apr 19, 1996 17:55:06 in article <execution speed of c++ versus c>,
  16. 'dons@math.missouri.edu (Don Steiger)' wrote: 
  17.  
  18.  
  19. >Has anybody run any tests comparing the execution speeds of optimized c++
  20. code 
  21. >versus optimized c code. 
  22.  
  23. I'm probably going to kick myself for responding to this topic 
  24. which pops up every month..... but, it's Saturday :-) 
  25.  
  26. Yes, I've run tests, and have found that equivalent code in  
  27. C and C++, compiled by equivalent compilers, will run at the 
  28. same speed.  Period. 
  29.  
  30. Now, what is (and isn't) equivalent? 
  31.  
  32. It's easy for new and lazy programmers to generate inefficient 
  33. code -- more so in C++ than in C.  C, therefore, sometimes 
  34. appears to be faster. 
  35.  
  36. C++ has possibilities for optimizations that are not available 
  37. in C.  For example, inline functions.  A C advocate will 
  38. point out that macros can be used to achieve the same 
  39. efficiency.  This is true, but who wants to deal with 
  40. macros -- especially complex ones written by someone else? 
  41. C++, therefore, appears to be faster. 
  42.  
  43. If trying to write using OO paradigm in both languages, 
  44. C++ has the potential to be faster by a small and insigni- 
  45. ficant margin.  Virtual function dispatch is usually 
  46. a nanosecond or two faster than a case statement in C. 
  47.  
  48. In the past, C compilers were better optimized than C++ 
  49. compilers.  After all, C had been around for years.  This, 
  50. IMHO, is no longer true to any significant extent. 
  51.  
  52. The bottom line:  If you're worried about efficiency, 
  53. concentrate on finding the appropriate algorithms and 
  54. profile your system to the hilt.  The returns you get 
  55. from that are an order of magnitude greater than from 
  56. choosing one language over the other. 
  57.  
  58. -- 
  59. Pete Grant 
  60. Kalevi, Inc. 
  61. Software Engineering & development
  62.